import { _decorator, Button, Component, Label, Node, Sprite,js } from 'cc';
import { UIComponent } from 'db://assets/scripts/platform/ui/UIComponent';
import { bind } from '../../../../platform/ui/UIDecorator';
import { Tb_GameList } from '../../../tb/Tb_GameList';
import { ResManager } from '../../../../platform/resources/ResMgr';
import UIMgr from '../../../../platform/ui/UIMgr';
import { GameView } from '../../game/GameView';
const { ccclass, property } = _decorator;
//mvc
@ccclass('GameItem')
export class GameItem extends UIComponent {

    @bind(Label)
    hot_value:Label
    @bind(Button)
    rank:Button
    @bind(Button)
    chengjiu:Button
    @bind(Sprite)
    game_icon:Sprite
    @bind(Label)
    game_name:Label

    cfg:Tb_GameList = null
    init(cfg:Tb_GameList){
        this.cfg = cfg
        this.hot_value.string = (Math.random()*5+1).toFixed(2)+"k"
        this.rank.node.on(Button.EventType.CLICK,this.onRankClick,this)
        this.chengjiu.node.on(Button.EventType.CLICK,this.onChengjiuClick,this)
        ResManager.inst.loadBundleSprite(cfg.icon).then((spriteFrame)=>{
            this.game_icon.spriteFrame = spriteFrame;
        })
        this.game_name.string = cfg.name
        this.node.on(Button.EventType.CLICK,this.gameClick,this)
    }

    onRankClick(){
        console.log("点击了排行:"+this.cfg.name);
        //TODO 打开排行榜界面

    }
    onChengjiuClick(){
        console.log("点击了成就:"+this.cfg.name);
        //TODO 打开成就界面
    }
    gameClick(){
        console.log("点击了游戏:"+this.cfg.name);
        // js.getClassByName("GameView")
        //TODO 打开游戏详情界面
        UIMgr.ins.showUI(GameView,null,this.cfg)
    }
}


